package tests

import (
	"context"
	"testing"

	"atomgit.com/openlinksaas/easy_trace/config"
	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
	v1comm "go.opentelemetry.io/proto/otlp/common/v1"
	v1 "go.opentelemetry.io/proto/otlp/resource/v1"
	tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
)

func TestOtlp(t *testing.T) {
	client := otlptracegrpc.NewClient(otlptracegrpc.WithInsecure(), otlptracegrpc.WithEndpoint(config.DEFAULT_OTLP_GRPC_LISTEN_ADDR))
	err := client.Start(context.Background())
	if err != nil {
		t.Error(err)
		return
	}
	defer client.Stop(context.Background())

	spans := []*tracepb.ResourceSpans{
		{
			Resource: &v1.Resource{
				Attributes: []*v1comm.KeyValue{
					{
						Key: "res_key",
						Value: &v1comm.AnyValue{
							Value: &v1comm.AnyValue_IntValue{
								IntValue: 1,
							},
						},
					},
				},
			},
			ScopeSpans: []*tracepb.ScopeSpans{
				{
					Spans: []*tracepb.Span{
						{
							TraceId: []byte("1111111111111111"),
							SpanId:  []byte("22222222"),
							Name:    "aaaa",
						},
					},
				},
			},
		},
	}
	err = client.UploadTraces(context.Background(), spans)
	if err != nil {
		t.Error(err)
		return
	}
}
